/*
 * Copyright (C) 2018 Zhejiang xiaominfo Technology CO.,LTD.
 * All rights reserved.
 * Official Web Site: http://www.xiaominfo.com.
 * Developer Web Site: http://open.xiaominfo.com.
 */

package com.xiaominfo.oss.service.impl;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaominfo.oss.common.pojo.Pagination;
import com.xiaominfo.oss.module.dao.OSSDeveloperMapper;
import com.xiaominfo.oss.module.model.OSSAppInfo;
import com.xiaominfo.oss.module.model.OSSDeveloper;
import com.xiaominfo.oss.service.OSSDeveloperService;
import com.xiaominfo.oss.utils.PaginationUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/***
 *
 * @since:oss-server 1.0
 * @author <a href="mailto:xiaoymin@foxmail.com">xiaoymin@foxmail.com</a> 
 * 2018/06/17 12:13
 */
@Service
public class OSSDeveloperServiceImpl extends ServiceImpl<OSSDeveloperMapper,OSSDeveloper> implements OSSDeveloperService {

    @Resource
    OSSDeveloperMapper ossDeveloperMapper;

    @Override
    public OSSDeveloper queryByAppid(String appid, String appsecret) {
        QueryWrapper<OSSDeveloper> wrapper=new QueryWrapper<>();
        wrapper.eq("appid",appid);
        wrapper.eq("appsecret",appsecret);
        List<OSSDeveloper> list=ossDeveloperMapper.selectList(wrapper);
        if (list!=null&&list.size()>0){
            return list.get(0);
        }
        return null;
    }

    @Override
    public Pagination<OSSDeveloper> queryByPage(OSSDeveloper ossDeveloper, Integer current_page, Integer page_size) {
        QueryWrapper<OSSDeveloper> wrapper=new QueryWrapper<>();
      //  Integer count=ossDeveloperMapper.selectCount(wrapper);
        Page page = new Page((long) Convert.toInt(current_page, 1), (long)Convert.toInt(page_size, 10));
        Page page1 = ossDeveloperMapper.selectPage(page, wrapper);
        Pagination<OSSDeveloper> pagination= PaginationUtils.transfor(page1.getRecords(),Convert.toInt(page.getTotal()),current_page,page_size);

        return pagination;
    }

    @Override
    public List<OSSDeveloper> queryAllDevs() {
        return ossDeveloperMapper.selectList(new QueryWrapper<>());
    }
}
